using System;
using System.Collections.Generic;

namespace NDomain.Reflection
{
    public class AggregateInfo
    {
        private string name;
        private List<EntityInfo> entities = new List<EntityInfo>();
        private EntityInfo root;
        private List<ValueObjectInfo> valueObjects = new List<ValueObjectInfo>();

        public AggregateInfo(string name)
        {
            this.name = name;
        }

        public string Name
        {
            get { return name; }
        }

        public IList<EntityInfo> Entities
        {
            get { return entities.AsReadOnly(); }
        }

        public EntityInfo Root
        {
            get { return root; }
            internal set { root = value; }
        }

        public IList<ValueObjectInfo> ValueObjects
        {
            get { return valueObjects.AsReadOnly(); }
        }

        public void AddEntity(EntityInfo entity)
        {
            entities.Add(entity);
        }

        public void AddValueObject(ValueObjectInfo valueObjectInfo)
        {
            valueObjects.Add(valueObjectInfo);
        }

        public EntityInfo GetEntity(string entityName)
        {
            if (Root != null && Root.Name == entityName)
                return Root;
            else
                return entities.Find(delegate(EntityInfo e) { return e.Name == entityName; });
        }
    }
}